{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 人脸识别与计算机视觉文档实践\n",
    "\n",
    ">* 本周主要内容：人脸（Face） API文档不同平台对比与实践及计算机视觉入门（认知服务）\n",
    ">* 202009_API_人工智能与机器学习_week03\n",
    ">*  电子讲义设计者：许智超\n",
    "<br/>\n",
    "<br/>\n",
    "\n",
    "## 复习\n",
    "\n",
    "* 上周主要内容： \n",
    ">    * 1、API文档\n",
    ">    * 2、认知服务-人脸识别\n",
    ">    * 3、pandas黑魔法（json_normalize）\n",
    "-----\n",
    "* 提问、检查与扩展：\n",
    ">    * 1、上周的Azure face API随机检查2位同学，对于API文档是否有能力详细阅读？\n",
    ">    * 2、抽查2位同学，对于获取的数据用途有何思考？是否尝试其他平台（XXX API、XXX API）      \n",
    ">    * 3、扩展: 我们尝试抽取了4张图片，包含AB、ABC、BCD、ABCD四个人物特征，如何通过API检查数据差异？\n",
    "  \n",
    "\n",
    "-----\n",
    "## 本周学习目标：\n",
    "\n",
    "> $\\mathcal{1、Azure 认知服务-人脸集合演示}$     \n",
    "> $\\mathcal{2、Face++ 之 FaceSets 实践}$     \n",
    "> $\\mathcal{3、计算机视觉实践}$    \n",
    "\n",
    "\n",
    "\n",
    "## 学生权限\n",
    "\n",
    "* [访问学生权益](https://azure.microsoft.com/zh-cn/education/)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>\n",
       "/* 本电子讲义使用之CSS */\n",
       "div.code_cell {\n",
       "    background-color: #e5f1fe;\n",
       "}\n",
       "div.cell.selected {\n",
       "    background-color: #effee2;\n",
       "    font-size: 2rem;\n",
       "    line-height: 2.4rem;\n",
       "}\n",
       "div.cell.selected .rendered_html table {\n",
       "    font-size: 2rem !important;\n",
       "    line-height: 2.4rem !important;\n",
       "}\n",
       ".rendered_html pre code {\n",
       "    background-color: #C4E4ff;   \n",
       "    padding: 2px 25px;\n",
       "}\n",
       ".rendered_html pre {\n",
       "    background-color: #99c9ff;\n",
       "}\n",
       "div.code_cell .CodeMirror {\n",
       "    font-size: 2rem !important;\n",
       "    line-height: 2.4rem !important;\n",
       "}\n",
       ".rendered_html img, .rendered_html svg {\n",
       "    max-width: 50%;\n",
       "    height: auto;\n",
       "    float: center;\n",
       "}\n",
       "/* Gradient transparent - color - transparent */\n",
       "hr {\n",
       "    border: 0;\n",
       "    border-bottom: 1px dashed #ccc;\n",
       "}\n",
       ".emoticon{\n",
       "    font-size: 5rem;\n",
       "    line-height: 4.4rem;\n",
       "    text-align: center;\n",
       "    vertical-align: middle;\n",
       "}\n",
       "\n",
       "</style>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%html\n",
    "<style>\n",
    "/* 本电子讲义使用之CSS */\n",
    "div.code_cell {\n",
    "    background-color: #e5f1fe;\n",
    "}\n",
    "div.cell.selected {\n",
    "    background-color: #effee2;\n",
    "    font-size: 2rem;\n",
    "    line-height: 2.4rem;\n",
    "}\n",
    "div.cell.selected .rendered_html table {\n",
    "    font-size: 2rem !important;\n",
    "    line-height: 2.4rem !important;\n",
    "}\n",
    ".rendered_html pre code {\n",
    "    background-color: #C4E4ff;   \n",
    "    padding: 2px 25px;\n",
    "}\n",
    ".rendered_html pre {\n",
    "    background-color: #99c9ff;\n",
    "}\n",
    "div.code_cell .CodeMirror {\n",
    "    font-size: 2rem !important;\n",
    "    line-height: 2.4rem !important;\n",
    "}\n",
    ".rendered_html img, .rendered_html svg {\n",
    "    max-width: 50%;\n",
    "    height: auto;\n",
    "    float: center;\n",
    "}\n",
    "/* Gradient transparent - color - transparent */\n",
    "hr {\n",
    "    border: 0;\n",
    "    border-bottom: 1px dashed #ccc;\n",
    "}\n",
    ".emoticon{\n",
    "    font-size: 5rem;\n",
    "    line-height: 4.4rem;\n",
    "    text-align: center;\n",
    "    vertical-align: middle;\n",
    "}\n",
    "\n",
    "</style>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 复习\n",
    "\n",
    "> 1、回顾阅读API文档的关键点     \n",
    "> 2、正确阅读json数据 [jsonviewer.stack.hu(json转换检查数据)](http://jsonviewer.stack.hu)    \n",
    "> 3、pandas 中的json_normalize模块/函数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A-1 面部检测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# A-1 面部检测\n",
    "import requests\n",
    "# json\n",
    "import json\n",
    "\n",
    "# set to your own subscription key value\n",
    "zhang_key = \"d1e040531c60aaee6a68716f41f088db\"\n",
    "assert subscription_key\n",
    "\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://api-hjq.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文body\n",
    "image_url = 'https://gitee.com/Zhang-hai-qing/api_zuoyelianxiziliao/raw/master/jiejiezhaopian.jpg'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': zhang_key}\n",
    "\n",
    "# 请求参数parameters\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->bytes\n",
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# bytes or string   编码不同  *****  encoding =\"utf-8\"\n",
    "# response.text\n",
    "# response.content\n",
    "results = response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': 'f9984002-da51-4848-9d6f-2b6704ef6d9c',\n",
       "  'faceRectangle': {'top': 118, 'left': 144, 'width': 88, 'height': 88},\n",
       "  'faceAttributes': {'smile': 0.813,\n",
       "   'headPose': {'pitch': -3.4, 'roll': 1.4, 'yaw': 9.4},\n",
       "   'gender': 'male',\n",
       "   'age': 19.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.003,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.813,\n",
       "    'neutral': 0.184,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.21},\n",
       "   'exposure': {'exposureLevel': 'overExposure', 'value': 0.81},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.01},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.18,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'brown', 'confidence': 0.95},\n",
       "     {'color': 'black', 'confidence': 0.93},\n",
       "     {'color': 'other', 'confidence': 0.23},\n",
       "     {'color': 'blond', 'confidence': 0.23},\n",
       "     {'color': 'gray', 'confidence': 0.21},\n",
       "     {'color': 'red', 'confidence': 0.15},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '842a1b59-d5ff-42b7-8536-ab866028d2c1',\n",
       "  'faceRectangle': {'top': 117, 'left': 376, 'width': 64, 'height': 64},\n",
       "  'faceAttributes': {'smile': 0.456,\n",
       "   'headPose': {'pitch': -1.1, 'roll': -0.2, 'yaw': 6.6},\n",
       "   'gender': 'female',\n",
       "   'age': 22.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.001,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.456,\n",
       "    'neutral': 0.542,\n",
       "    'sadness': 0.001,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.16},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.58},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.01},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.08,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'other', 'confidence': 0.63},\n",
       "     {'color': 'brown', 'confidence': 0.46},\n",
       "     {'color': 'gray', 'confidence': 0.39},\n",
       "     {'color': 'blond', 'confidence': 0.03},\n",
       "     {'color': 'red', 'confidence': 0.01},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '6cd77b6d-f8fc-4ee5-be51-f915bdbc210b',\n",
       "  'faceRectangle': {'top': 41, 'left': 676, 'width': 52, 'height': 52},\n",
       "  'faceAttributes': {'smile': 1.0,\n",
       "   'headPose': {'pitch': 3.0, 'roll': -1.3, 'yaw': -0.6},\n",
       "   'gender': 'male',\n",
       "   'age': 25.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'ReadingGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 1.0,\n",
       "    'neutral': 0.0,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.66},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.07},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 1.0}],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.06,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.98},\n",
       "     {'color': 'brown', 'confidence': 0.96},\n",
       "     {'color': 'other', 'confidence': 0.22},\n",
       "     {'color': 'gray', 'confidence': 0.21},\n",
       "     {'color': 'red', 'confidence': 0.09},\n",
       "     {'color': 'blond', 'confidence': 0.08},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '5f96f25b-4969-49d6-ab21-998fb3b07f7d',\n",
       "  'faceRectangle': {'top': 69, 'left': 445, 'width': 52, 'height': 52},\n",
       "  'faceAttributes': {'smile': 1.0,\n",
       "   'headPose': {'pitch': 0.2, 'roll': 2.6, 'yaw': 1.5},\n",
       "   'gender': 'female',\n",
       "   'age': 23.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 1.0,\n",
       "    'neutral': 0.0,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.56},\n",
       "   'noise': {'noiseLevel': 'medium', 'value': 0.33},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.11,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'brown', 'confidence': 0.81},\n",
       "     {'color': 'other', 'confidence': 0.41},\n",
       "     {'color': 'gray', 'confidence': 0.37},\n",
       "     {'color': 'blond', 'confidence': 0.03},\n",
       "     {'color': 'red', 'confidence': 0.02},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '8bb0d7e8-008f-43d5-b649-0c46c69b15b4',\n",
       "  'faceRectangle': {'top': 95, 'left': 238, 'width': 51, 'height': 51},\n",
       "  'faceAttributes': {'smile': 0.981,\n",
       "   'headPose': {'pitch': 7.2, 'roll': 1.2, 'yaw': 2.6},\n",
       "   'gender': 'female',\n",
       "   'age': 18.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'ReadingGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.981,\n",
       "    'neutral': 0.019,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.07},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.69},\n",
       "   'noise': {'noiseLevel': 'medium', 'value': 0.48},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 1.0}],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.11,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.98},\n",
       "     {'color': 'brown', 'confidence': 0.86},\n",
       "     {'color': 'other', 'confidence': 0.4},\n",
       "     {'color': 'gray', 'confidence': 0.36},\n",
       "     {'color': 'blond', 'confidence': 0.09},\n",
       "     {'color': 'red', 'confidence': 0.08},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': 'a511e7e1-ec6d-4123-9f0b-734e036cf242',\n",
       "  'faceRectangle': {'top': 94, 'left': 540, 'width': 48, 'height': 48},\n",
       "  'faceAttributes': {'smile': 1.0,\n",
       "   'headPose': {'pitch': -7.7, 'roll': 5.0, 'yaw': 6.9},\n",
       "   'gender': 'female',\n",
       "   'age': 19.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 1.0,\n",
       "    'neutral': 0.0,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.08},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.65},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.08},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.1,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'brown', 'confidence': 0.88},\n",
       "     {'color': 'other', 'confidence': 0.35},\n",
       "     {'color': 'gray', 'confidence': 0.33},\n",
       "     {'color': 'blond', 'confidence': 0.05},\n",
       "     {'color': 'red', 'confidence': 0.04},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}}]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A-2 json转译\n",
    "\n",
    "> * bytes ---> json\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': '9edd9c50-88e9-47cc-82b8-267663074a52',\n",
       "  'faceRectangle': {'top': 118, 'left': 144, 'width': 88, 'height': 88},\n",
       "  'faceAttributes': {'smile': 0.813,\n",
       "   'headPose': {'pitch': -3.4, 'roll': 1.4, 'yaw': 9.4},\n",
       "   'gender': 'male',\n",
       "   'age': 19.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.003,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.813,\n",
       "    'neutral': 0.184,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.21},\n",
       "   'exposure': {'exposureLevel': 'overExposure', 'value': 0.81},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.01},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.18,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'brown', 'confidence': 0.95},\n",
       "     {'color': 'black', 'confidence': 0.93},\n",
       "     {'color': 'other', 'confidence': 0.23},\n",
       "     {'color': 'blond', 'confidence': 0.23},\n",
       "     {'color': 'gray', 'confidence': 0.21},\n",
       "     {'color': 'red', 'confidence': 0.15},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '9891c134-9db9-4517-9e5d-5bea1ee57f45',\n",
       "  'faceRectangle': {'top': 117, 'left': 376, 'width': 64, 'height': 64},\n",
       "  'faceAttributes': {'smile': 0.456,\n",
       "   'headPose': {'pitch': -1.1, 'roll': -0.2, 'yaw': 6.6},\n",
       "   'gender': 'female',\n",
       "   'age': 22.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.001,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.456,\n",
       "    'neutral': 0.542,\n",
       "    'sadness': 0.001,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.16},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.58},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.01},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.08,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'other', 'confidence': 0.63},\n",
       "     {'color': 'brown', 'confidence': 0.46},\n",
       "     {'color': 'gray', 'confidence': 0.39},\n",
       "     {'color': 'blond', 'confidence': 0.03},\n",
       "     {'color': 'red', 'confidence': 0.01},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '09f29908-5ee1-4d59-a4a0-76a7eac3f01b',\n",
       "  'faceRectangle': {'top': 41, 'left': 676, 'width': 52, 'height': 52},\n",
       "  'faceAttributes': {'smile': 1.0,\n",
       "   'headPose': {'pitch': 3.0, 'roll': -1.3, 'yaw': -0.6},\n",
       "   'gender': 'male',\n",
       "   'age': 25.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'ReadingGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 1.0,\n",
       "    'neutral': 0.0,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.66},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.07},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 1.0}],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.06,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.98},\n",
       "     {'color': 'brown', 'confidence': 0.96},\n",
       "     {'color': 'other', 'confidence': 0.22},\n",
       "     {'color': 'gray', 'confidence': 0.21},\n",
       "     {'color': 'red', 'confidence': 0.09},\n",
       "     {'color': 'blond', 'confidence': 0.08},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': 'c609d2a5-a263-4f3f-b391-53f98c221526',\n",
       "  'faceRectangle': {'top': 69, 'left': 445, 'width': 52, 'height': 52},\n",
       "  'faceAttributes': {'smile': 1.0,\n",
       "   'headPose': {'pitch': 0.2, 'roll': 2.6, 'yaw': 1.5},\n",
       "   'gender': 'female',\n",
       "   'age': 23.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 1.0,\n",
       "    'neutral': 0.0,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.0},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.56},\n",
       "   'noise': {'noiseLevel': 'medium', 'value': 0.33},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.11,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'brown', 'confidence': 0.81},\n",
       "     {'color': 'other', 'confidence': 0.41},\n",
       "     {'color': 'gray', 'confidence': 0.37},\n",
       "     {'color': 'blond', 'confidence': 0.03},\n",
       "     {'color': 'red', 'confidence': 0.02},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '90c89dbf-74b8-4aa4-bcdc-cb0747843479',\n",
       "  'faceRectangle': {'top': 95, 'left': 238, 'width': 51, 'height': 51},\n",
       "  'faceAttributes': {'smile': 0.981,\n",
       "   'headPose': {'pitch': 7.2, 'roll': 1.2, 'yaw': 2.6},\n",
       "   'gender': 'female',\n",
       "   'age': 18.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'ReadingGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.981,\n",
       "    'neutral': 0.019,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.07},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.69},\n",
       "   'noise': {'noiseLevel': 'medium', 'value': 0.48},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [{'type': 'glasses', 'confidence': 1.0}],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.11,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.98},\n",
       "     {'color': 'brown', 'confidence': 0.86},\n",
       "     {'color': 'other', 'confidence': 0.4},\n",
       "     {'color': 'gray', 'confidence': 0.36},\n",
       "     {'color': 'blond', 'confidence': 0.09},\n",
       "     {'color': 'red', 'confidence': 0.08},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '0b217a5a-1b42-420e-800a-c291420b1e49',\n",
       "  'faceRectangle': {'top': 94, 'left': 540, 'width': 48, 'height': 48},\n",
       "  'faceAttributes': {'smile': 1.0,\n",
       "   'headPose': {'pitch': -7.7, 'roll': 5.0, 'yaw': 6.9},\n",
       "   'gender': 'female',\n",
       "   'age': 19.0,\n",
       "   'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 1.0,\n",
       "    'neutral': 0.0,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'low', 'value': 0.08},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.65},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.08},\n",
       "   'makeup': {'eyeMakeup': False, 'lipMakeup': False},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.1,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 1.0},\n",
       "     {'color': 'brown', 'confidence': 0.88},\n",
       "     {'color': 'other', 'confidence': 0.35},\n",
       "     {'color': 'gray', 'confidence': 0.33},\n",
       "     {'color': 'blond', 'confidence': 0.05},\n",
       "     {'color': 'red', 'confidence': 0.04},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}}]"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# A-2\n",
    "results = response.json()\n",
    "results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A-3 pandas 数据表格化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_face = pd.json_normalize(results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A-4 数据取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['9edd9c50-88e9-47cc-82b8-267663074a52',\n",
       " '9891c134-9db9-4517-9e5d-5bea1ee57f45',\n",
       " '09f29908-5ee1-4d59-a4a0-76a7eac3f01b',\n",
       " 'c609d2a5-a263-4f3f-b391-53f98c221526',\n",
       " '90c89dbf-74b8-4aa4-bcdc-cb0747843479',\n",
       " '0b217a5a-1b42-420e-800a-c291420b1e49']"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "faceID = df_face['faceId'].values.tolist()\n",
    "faceID "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['faceId', 'faceRectangle.top', 'faceRectangle.left',\n",
       "       'faceRectangle.width', 'faceRectangle.height', 'faceAttributes.smile',\n",
       "       'faceAttributes.headPose.pitch', 'faceAttributes.headPose.roll',\n",
       "       'faceAttributes.headPose.yaw', 'faceAttributes.gender',\n",
       "       'faceAttributes.age', 'faceAttributes.facialHair.moustache',\n",
       "       'faceAttributes.facialHair.beard',\n",
       "       'faceAttributes.facialHair.sideburns', 'faceAttributes.glasses',\n",
       "       'faceAttributes.emotion.anger', 'faceAttributes.emotion.contempt',\n",
       "       'faceAttributes.emotion.disgust', 'faceAttributes.emotion.fear',\n",
       "       'faceAttributes.emotion.happiness', 'faceAttributes.emotion.neutral',\n",
       "       'faceAttributes.emotion.sadness', 'faceAttributes.emotion.surprise',\n",
       "       'faceAttributes.blur.blurLevel', 'faceAttributes.blur.value',\n",
       "       'faceAttributes.exposure.exposureLevel',\n",
       "       'faceAttributes.exposure.value', 'faceAttributes.noise.noiseLevel',\n",
       "       'faceAttributes.noise.value', 'faceAttributes.makeup.eyeMakeup',\n",
       "       'faceAttributes.makeup.lipMakeup', 'faceAttributes.accessories',\n",
       "       'faceAttributes.occlusion.foreheadOccluded',\n",
       "       'faceAttributes.occlusion.eyeOccluded',\n",
       "       'faceAttributes.occlusion.mouthOccluded', 'faceAttributes.hair.bald',\n",
       "       'faceAttributes.hair.invisible', 'faceAttributes.hair.hairColor'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查属性/特征值\n",
    "df_face.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>faceId</th>\n",
       "      <th>faceAttributes.glasses</th>\n",
       "      <th>faceAttributes.emotion.neutral</th>\n",
       "      <th>faceAttributes.age</th>\n",
       "      <th>faceAttributes.gender</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9edd9c50-88e9-47cc-82b8-267663074a52</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.184</td>\n",
       "      <td>19.0</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9891c134-9db9-4517-9e5d-5bea1ee57f45</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.542</td>\n",
       "      <td>22.0</td>\n",
       "      <td>female</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>09f29908-5ee1-4d59-a4a0-76a7eac3f01b</td>\n",
       "      <td>ReadingGlasses</td>\n",
       "      <td>0.000</td>\n",
       "      <td>25.0</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>c609d2a5-a263-4f3f-b391-53f98c221526</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.000</td>\n",
       "      <td>23.0</td>\n",
       "      <td>female</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>90c89dbf-74b8-4aa4-bcdc-cb0747843479</td>\n",
       "      <td>ReadingGlasses</td>\n",
       "      <td>0.019</td>\n",
       "      <td>18.0</td>\n",
       "      <td>female</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0b217a5a-1b42-420e-800a-c291420b1e49</td>\n",
       "      <td>NoGlasses</td>\n",
       "      <td>0.000</td>\n",
       "      <td>19.0</td>\n",
       "      <td>female</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 faceId faceAttributes.glasses  \\\n",
       "0  9edd9c50-88e9-47cc-82b8-267663074a52              NoGlasses   \n",
       "1  9891c134-9db9-4517-9e5d-5bea1ee57f45              NoGlasses   \n",
       "2  09f29908-5ee1-4d59-a4a0-76a7eac3f01b         ReadingGlasses   \n",
       "3  c609d2a5-a263-4f3f-b391-53f98c221526              NoGlasses   \n",
       "4  90c89dbf-74b8-4aa4-bcdc-cb0747843479         ReadingGlasses   \n",
       "5  0b217a5a-1b42-420e-800a-c291420b1e49              NoGlasses   \n",
       "\n",
       "   faceAttributes.emotion.neutral  faceAttributes.age faceAttributes.gender  \n",
       "0                           0.184                19.0                  male  \n",
       "1                           0.542                22.0                female  \n",
       "2                           0.000                25.0                  male  \n",
       "3                           0.000                23.0                female  \n",
       "4                           0.019                18.0                female  \n",
       "5                           0.000                19.0                female  "
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 可观察其中几组数据\n",
    "df_face[['faceId','faceAttributes.glasses','faceAttributes.emotion.neutral','faceAttributes.age','faceAttributes.gender']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Azure 认知服务-人脸演示"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 试一试：人脸验证(难)\n",
    "\n",
    "\n",
    "\n",
    ">* API人脸文档中最重要的组成部分：\n",
    " >>* Request URL？\n",
    " >>* Http Method？\n",
    " >>* 参数？\n",
    "\n",
    "----\n",
    ">* 不同的人脸对比数据\n",
    "  >>* 人脸验证关键数据？\n",
    "  >>* 根据哪些数据证明是同一个人？\n",
    "    \n",
    "----\n",
    ">* 具体步骤：\n",
    "  >>* 1、Create 请求成功200 返回空字符串\n",
    "  >>* 2、Add face 请求成功200 返回persistedFaceId\n",
    "  >>* 3、Detect 准备 被检测人 人脸的id\n",
    "  >>* 4、Find similars 返回相似置信度\n",
    "  >>* 附加：get查看facelists\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "- [API中文文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/facelist/create#code-try-0)\n",
    "- [API英文文档](https://southeastasia.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039524b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1、Create 请求成功200 返回空字符串\n",
    "> 在开始检测之前，我们需要构建一个列表用于装取我们需要进行对比的人脸\n",
    "- [创建人脸列表api文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/facelist/create)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "# 1、create  列表\n",
    "# faceListId\n",
    "faceListId =  'echo__test'#学生填写\n",
    "create_facelists_url = 'https://api-hjq.cognitiveservices.azure.com//face/v1.0/facelists/{}' #学生填写\n",
    "zhang_key = \"d1e040531c60aaee6a68716f41f088db\"#学生填写\n",
    "assert zhang_key\n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-zhang-Key': subscription_key,\n",
    "}\n",
    "data = {\"name\": \"haiqing_2\",\n",
    "  \"userData\": \"classmate.\",\n",
    "  \"recognitionModel\": \"recognition_01\"\n",
    "# 学生填写\n",
    "    \n",
    "}\n",
    "\n",
    "r_create = requests.put(create_facelists_url.format(faceListId),headers=headers,json=data) #学生填写\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"error\":{\"code\":\"QuotaExceeded\",\"message\":\"Face List number reached limit. (Parameter \\'faceListCount\\')\"}}'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_create.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 已经成功创建facelist（云端/云计算）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2、Add face 请求成功200 返回persistedFaceId\n",
    "> 我们通过上面的步骤建好了一个脸的列表，接下来我们要给这个列表添加脸了！把我们想要对比的脸存进列表吧\n",
    "- [添加人脸进列表api文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/facelist/addfacefromurl)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "#先加一张脸试试\n",
    "# 2、Add face\n",
    "add_face_url = \"https://api-hjq.cognitiveservices.azure.com//face/v1.0/facelists/echo__test/persistedfaces\"#学生填写\n",
    "\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': zhang_key,\n",
    "}\n",
    "img_url = \"d1e040531c60aaee6a68716f41f088db\"#学生填写\n",
    "\n",
    "params_add_face={\n",
    "    \"ueserData\":\"Zhang_hai_qing\"\n",
    "#学生填写\n",
    "}\n",
    "\n",
    "r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})#学生填写)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "r_add_face.json()#返回persistedFaceId"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 扩展内容，封装成函数方便多次使用 *\n",
    "> 我们要添加多张脸，但是为了减少代码量，我们可以把代码封装成函数，避免每次都要写一大堆代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装成函数方便添加图片\n",
    "def AddFace(img_url=str,userData=str):\n",
    "    add_face_url =\"https://api-hjq.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedFaces\"\n",
    "    assert zhang_key\n",
    "    headers = {\n",
    "        # Request headers\n",
    "        'Content-Type': 'application/json',\n",
    "        'Ocp-Apim-Zhang-Key': subscription_key,\n",
    "    }\n",
    "    img_url = img_url\n",
    "\n",
    "    params_add_face={\n",
    "        \"userData\":userData\n",
    "    }\n",
    "    r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "    return r_add_face.status_code#返回出状态码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/Autumnhui.jpg\",\"丘天惠\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/L-Tony-info.jpg\",\"林嘉茵\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/TLINGP.jpg\",\"汤玲萍\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/WenYanZeng.jpg\",\"曾雯燕\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/XIEIC.jpg\",\"谢依希\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/YuecongYang.png\",\"杨悦聪\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/Zoezhouyu.jpg\",\"周雨\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/crayon-heimi.jpg\",\"刘瑜鹏\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/jiayichen.jpg\",\"陈嘉仪\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/kg2000.jpg\",\"徐旖芊\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/liuxinrujiayou.jpg\",\"刘心如\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/liuyu19.png\",\"刘宇\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/ltco.jpg\",\"李婷\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/lucaszy.jpg\",\"黄智毅\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/pingzi0211.jpg\",\"黄慧文\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/shmimy-cn.jpg\",\"张铭睿\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/yichenting.jpg\",\"陈婷\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/coco022.jpg\",\"洪可凡\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/lujizhi.png\",\"卢继志\")\n",
    "AddFace(\"http://huangjieqi.gitee.io/picture_storage/zzlhyy.jpg\",\"张梓乐\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 附加：get查看facelists\n",
    "> 查看列表\n",
    "- [查看人脸列表api文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/facelist/get)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': 'ddaca2b2-f86d-4926-8c7f-aa19da01fbeb'},\n",
       "  {'persistedFaceId': '10dcb826-edae-40e1-9281-474892dde29c',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': 'f16649cc-8942-481c-8cda-9d62736c39f8',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': '8b66fd3c-0563-48d0-b7a6-13720fbecd25',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': '7073c042-9fc1-4c28-8c6c-b1ac29d2f81b',\n",
       "   'userData': '曾雯燕'},\n",
       "  {'persistedFaceId': '77711d80-f35a-4705-8576-66a404a46e2c',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': '03d9ec78-f741-44c1-8fb8-91813332474a',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': 'edc3a19a-978c-4315-b6e0-bedde0b185c3',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': '11f9604b-014b-4e0e-9b13-41e8504596b5',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': '341ee5c1-b890-4a8b-807f-1df165b74360',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': 'f3d3de02-54d0-42ba-988c-bc68cdd807bf',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': 'f6e4e112-72ff-47fa-9c29-cb9956264c10',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': '82c90d48-4b87-49f8-ba96-83614b31e3f1',\n",
       "   'userData': '刘宇'},\n",
       "  {'persistedFaceId': 'f5afa81f-4f51-4c15-9739-47bf2d8b2121',\n",
       "   'userData': '李婷'},\n",
       "  {'persistedFaceId': '87438894-90e0-4db8-a1d4-1ada6e4111f1',\n",
       "   'userData': '黄智毅'},\n",
       "  {'persistedFaceId': 'edc9be92-9efc-44a8-a166-f06bd423d88a',\n",
       "   'userData': '黄慧文'},\n",
       "  {'persistedFaceId': '687a45a5-b41f-4c18-8831-5fe36fcd4d4d',\n",
       "   'userData': '张铭睿'},\n",
       "  {'persistedFaceId': '6d866bd0-f6b8-461c-8b8f-65e9104056da',\n",
       "   'userData': '陈婷'},\n",
       "  {'persistedFaceId': 'aac5c519-6526-423d-b739-5d13a41c6724',\n",
       "   'userData': '洪可凡'},\n",
       "  {'persistedFaceId': '4dc9f68e-8976-4d14-985f-a283bf0de468',\n",
       "   'userData': '卢继志'},\n",
       "  {'persistedFaceId': '3d633965-80b9-4024-b34e-ff5869997613',\n",
       "   'userData': '张梓乐'},\n",
       "  {'persistedFaceId': '03d66525-9d46-4003-ac6d-bdbd0ec82b89'},\n",
       "  {'persistedFaceId': 'e8b2cc57-c11b-4968-97e9-4aa841046a27'},\n",
       "  {'persistedFaceId': '2369ab29-4db9-4762-81b7-2a968fab1c44'},\n",
       "  {'persistedFaceId': '16770e38-33e0-4a46-8ca9-e997f57445b4'},\n",
       "  {'persistedFaceId': '814dbbdf-6c61-4c82-a6f3-ba4eea25fbbc'},\n",
       "  {'persistedFaceId': '87c995bf-b6ed-42b7-9efc-bd9a23b3a173'},\n",
       "  {'persistedFaceId': 'ec36e901-0d08-4484-980f-608af18dbd00',\n",
       "   'userData': '丘天惠'},\n",
       "  {'persistedFaceId': '6d7ecba4-52b5-4693-ab31-31b64253b008',\n",
       "   'userData': '林嘉茵'},\n",
       "  {'persistedFaceId': '15e2202b-02e4-4425-9d6b-0958f5685986',\n",
       "   'userData': '汤玲萍'},\n",
       "  {'persistedFaceId': 'c498de55-21ad-4117-ab64-f9c5c20271d0',\n",
       "   'userData': '谢依希'},\n",
       "  {'persistedFaceId': 'f9b2d50e-5790-47f3-abb9-8c71b074d552',\n",
       "   'userData': '杨悦聪'},\n",
       "  {'persistedFaceId': '3a24e48c-4c9c-42b2-a3ca-76f05e0e3ccf',\n",
       "   'userData': '周雨'},\n",
       "  {'persistedFaceId': '9ee733a4-bebd-4548-9c2a-8a2cd89ed55c',\n",
       "   'userData': '刘瑜鹏'},\n",
       "  {'persistedFaceId': 'd4814ff5-82c3-4772-8eb6-716c9cfe3c13',\n",
       "   'userData': '陈嘉仪'},\n",
       "  {'persistedFaceId': 'e1453e05-a546-4609-9099-a76b636686fd',\n",
       "   'userData': '徐旖芊'},\n",
       "  {'persistedFaceId': 'b087578b-add3-4e8b-a236-3b93f0ef8726',\n",
       "   'userData': '刘心如'},\n",
       "  {'persistedFaceId': '7f1e52d5-a1a6-457b-b374-c1dccadc57e9',\n",
       "   'userData': '刘宇'},\n",
       "  {'persistedFaceId': '9a432a9d-0310-468b-88c3-671f54237d35',\n",
       "   'userData': '李婷'},\n",
       "  {'persistedFaceId': '58a41669-f351-493d-b45a-aff01ce27616',\n",
       "   'userData': '黄智毅'},\n",
       "  {'persistedFaceId': 'b45815bf-eaca-42bc-aaa7-a0524fd49f29',\n",
       "   'userData': '黄慧文'},\n",
       "  {'persistedFaceId': 'd0501da4-46aa-47ec-888e-ba809520efeb',\n",
       "   'userData': '张铭睿'},\n",
       "  {'persistedFaceId': '58ca89a4-d906-419b-959c-f37f6528c400',\n",
       "   'userData': '陈婷'},\n",
       "  {'persistedFaceId': '8f535a7e-670c-46a0-9dc6-809f30282b08',\n",
       "   'userData': '洪可凡'},\n",
       "  {'persistedFaceId': 'f0f3cebd-0ab3-4a87-b1b6-1c3616252fd4',\n",
       "   'userData': '卢继志'},\n",
       "  {'persistedFaceId': '31e8bc08-bec5-4146-9476-c149a169268a',\n",
       "   'userData': '张梓乐'}],\n",
       " 'faceListId': 'echo__test',\n",
       " 'name': 'sample_list',\n",
       " 'userData': 'User-provided data attached to the face list.'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Get facelist\n",
    "get_facelist_url = \"https://api-hjq.cognitiveservices.azure.com/face/v1.0/facelists/echo__test\"#学生填写\n",
    "r_get_facelist = requests.get(get_facelist_url,headers=headers)#学生填写\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、Detect 准备 被检测人 人脸的id\n",
    "> 删除分为两种，一种为删除人脸ID，一种为删除人脸列表\n",
    "- [删除人脸列表api文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/facelist/delete)\n",
    "- [删除人脸ID api文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/facelist/deleteface)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "faceListId = #删除人脸列表 # 学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Detect face 删除列表内人脸id\n",
    "delete_face_url =\" https://api-hjq.cognitiveservices.azure.com/face/v1.0/facelists/echo__test\"\n",
    "\n",
    "assert zhang_key\n",
    "persistedFaceId = r_add_face.json()[\"persistedFaceId\"]\n",
    "# 直接取上面获得的ID{'persistedFaceId': 'f18450d3-60d2-45f3-a69e-783574dc3ce8'} \n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "\n",
    "# 注意requests请求为delete\n",
    "r_delete_face = requests.delete()#学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_delete_face"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Detect face 删除列表内人脸列表\n",
    "delete_face_url =#学生填写\n",
    "assert zhang_key\n",
    "\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Zhang-Key': subscription_key,\n",
    "}\n",
    "\n",
    "# format内直接删除\n",
    "# 注意requests请求为delete\n",
    "r_delete_facelist = requests.delete()#学生填写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_delete_facelist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4、Find similars 返回相似置信度\n",
    "- [监测人脸相似度api文档](https://docs.microsoft.com/zh-cn/rest/api/cognitiveservices/face/face/findsimilar)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': 'afd9522c-d4bb-4d86-9717-ef73efe0767a',\n",
       "  'faceRectangle': {'top': 595, 'left': 465, 'width': 258, 'height': 258},\n",
       "  'faceAttributes': {'smile': 0.024,\n",
       "   'headPose': {'pitch': 11.0, 'roll': 11.0, 'yaw': 4.3},\n",
       "   'gender': 'male',\n",
       "   'age': 20.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.001,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.024,\n",
       "    'neutral': 0.959,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.015},\n",
       "   'blur': {'blurLevel': 'medium', 'value': 0.33},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.71},\n",
       "   'noise': {'noiseLevel': 'high', 'value': 0.73},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.2,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'black', 'confidence': 0.98},\n",
       "     {'color': 'brown', 'confidence': 0.98},\n",
       "     {'color': 'blond', 'confidence': 0.17},\n",
       "     {'color': 'other', 'confidence': 0.15},\n",
       "     {'color': 'red', 'confidence': 0.14},\n",
       "     {'color': 'gray', 'confidence': 0.06},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}}]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3、检测人脸的id\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://api-hjq.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文\n",
    "image_url = 'https://gitee.com/Zhang-hai-qing/api_zuoyelianxiziliao/raw/master/jiejiezhaopian.jpg'\n",
    "\n",
    "headers = {'Ocp-Zhang-Key': subscription_key}\n",
    "\n",
    "# 请求参数\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 选择model\n",
    "    'recognitionModel':'recognition_03',#此参数需与facelist参数一致\n",
    "    'detectionModel':'detection_01',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->字符串\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "findsimilars_url = \"https://api-hjq.cognitiveservices.azure.com/face/v1.0/findsimilars\"\n",
    "\n",
    "# 请求正文 faceId需要先检测一张照片获取\n",
    "data_findsimilars = {\n",
    "    \"faceId\":'afd9522c-d4bb-4d86-9717-ef73efe0767a',#取上方的faceID\n",
    "    \"faceListId\":  'echo__test',\n",
    "    \"maxNumOfCandidatesReturned\": 10,\n",
    "    \"mode\": \"matchFace\"#matchPerson #一种为验证模式，一种为相似值模式\n",
    "    }\n",
    "\n",
    "r_findsimilars = requests.post(findsimilars_url,headers=headers,json=data_findsimilars)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'persistedFaceId': '78f2eb76-0db7-4b9b-a46c-23c52661134a',\n",
       "  'confidence': 0.29269},\n",
       " {'persistedFaceId': '297ae90b-9e11-4375-a6dc-f16c52446637',\n",
       "  'confidence': 0.20908},\n",
       " {'persistedFaceId': 'ddc744e3-583f-408d-b249-8aeac83b546d',\n",
       "  'confidence': 0.17849},\n",
       " {'persistedFaceId': '6be2eee6-1015-4741-9620-a2c3fa06aedb',\n",
       "  'confidence': 0.16209},\n",
       " {'persistedFaceId': 'fafb402e-3d0d-418b-9dec-da6ae893b677',\n",
       "  'confidence': 0.15023},\n",
       " {'persistedFaceId': 'd9855ce5-1ce9-4600-b18c-44066531618f',\n",
       "  'confidence': 0.101},\n",
       " {'persistedFaceId': '3d6de908-a09a-40d5-bd72-547517e3da17',\n",
       "  'confidence': 0.10034},\n",
       " {'persistedFaceId': 'bbf65461-1e33-4ec3-9fe7-e7de4539e4db',\n",
       "  'confidence': 0.0999},\n",
       " {'persistedFaceId': '9ff39ef7-ecb4-455b-8523-5398d0c8ec31',\n",
       "  'confidence': 0.09955},\n",
       " {'persistedFaceId': '83a0fc70-314a-4905-927b-6b9f7d5ac0a5',\n",
       "  'confidence': 0.09503}]"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#facelist里面的数据\n",
    "adf = pd.json_normalize(r_get_facelist.json()[\"persistedFaces\"])# 升级pandas才能运行\n",
    "adf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>78f2eb76-0db7-4b9b-a46c-23c52661134a</td>\n",
       "      <td>0.29269</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>297ae90b-9e11-4375-a6dc-f16c52446637</td>\n",
       "      <td>0.20908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ddc744e3-583f-408d-b249-8aeac83b546d</td>\n",
       "      <td>0.17849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6be2eee6-1015-4741-9620-a2c3fa06aedb</td>\n",
       "      <td>0.16209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>fafb402e-3d0d-418b-9dec-da6ae893b677</td>\n",
       "      <td>0.15023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>d9855ce5-1ce9-4600-b18c-44066531618f</td>\n",
       "      <td>0.10100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>3d6de908-a09a-40d5-bd72-547517e3da17</td>\n",
       "      <td>0.10034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>bbf65461-1e33-4ec3-9fe7-e7de4539e4db</td>\n",
       "      <td>0.09990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9ff39ef7-ecb4-455b-8523-5398d0c8ec31</td>\n",
       "      <td>0.09955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>83a0fc70-314a-4905-927b-6b9f7d5ac0a5</td>\n",
       "      <td>0.09503</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId  confidence\n",
       "0  78f2eb76-0db7-4b9b-a46c-23c52661134a     0.29269\n",
       "1  297ae90b-9e11-4375-a6dc-f16c52446637     0.20908\n",
       "2  ddc744e3-583f-408d-b249-8aeac83b546d     0.17849\n",
       "3  6be2eee6-1015-4741-9620-a2c3fa06aedb     0.16209\n",
       "4  fafb402e-3d0d-418b-9dec-da6ae893b677     0.15023\n",
       "5  d9855ce5-1ce9-4600-b18c-44066531618f     0.10100\n",
       "6  3d6de908-a09a-40d5-bd72-547517e3da17     0.10034\n",
       "7  bbf65461-1e33-4ec3-9fe7-e7de4539e4db     0.09990\n",
       "8  9ff39ef7-ecb4-455b-8523-5398d0c8ec31     0.09955\n",
       "9  83a0fc70-314a-4905-927b-6b9f7d5ac0a5     0.09503"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 返回相似度的数据\n",
    "bdf = pd.json_normalize(r_findsimilars.json())# 升级pandas才能运行\n",
    "bdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#合并在一起，得出班级能谁最像你\n",
    "pd.merge(adf, bdf,how='inner', on='persistedFaceId').sort_values(by=\"confidence\",ascending = False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Face++ FaceSets 实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 计算机视觉实践与练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "302px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
